package com.zhoufy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.mongodb.core.MongoTemplate;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA by ChouFy on 2020-08-02.
 *
 * @author chouFy
 */
@SpringBootApplication
public class MongoDatabasesSpringBootTemplateDemo {


    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(MongoDatabasesSpringBootTemplateDemo.class, args);

        MongoTemplate bean = run.getBean(MongoTemplate.class);

        if (bean == null) {
            System.out.println("is null");
        } else {
            System.out.println("is not null");
        }

//          插入部分
        for (int i = 0; i < 10; i++) {
            Resume resume = new Resume();
            resume.setName("test" + i);
            resume.setCity("bj");
            resume.setExpectSalary(15000.0D);
            resume.setBirthday(new Date());
            bean.save(resume);
        }


        //  查询
        List<Resume> all = bean.findAll(Resume.class);
        for (Resume resume : all) {
            System.out.println(resume.getId() + " , " + resume.getName());
        }

    }
}
